package com.wu.ssm.mybatis.binding;

import com.wu.ssm.mybatis.MySqlSession;
import org.apache.ibatis.binding.BindingException;
import org.apache.ibatis.mapping.SqlCommandType;


/**
 * Created by wzf on 2018/11/14/014.
 */
public class MyMapperMethod {

    private final SqlCommand command;

    public MyMapperMethod(SqlCommand command) {
        this.command = command;
    }

    public static class SqlCommand {

        private final String name;
        private final SqlCommandType type;

        public SqlCommand(String name, SqlCommandType type) {
            this.name = name;
            this.type = type;
        }
        public String getName() {
            return name;
        }
        public SqlCommandType getType() {
            return type;
        }
    }
    public Object execute(MySqlSession sqlSession, Object [] args){

        Object result = null;
        switch (command.getType()){
            case INSERT:{
                break;
            }
            case SELECT:{
                result =sqlSession.selectOne(command.getName(),args);
                break;
            }
            default:
                throw new BindingException("Unknown execution method for: " + command.getName());
        }

        return result;
    }

}
